import { userAccountLogin } from '@/api/user'

// 用户信息数据管理
const user = {
  namespaced: true,
  state: () => ({
    profile: {
      id: '',
      account: '',
      nickname: '',
      avatar: '',
      token: '',
      mobile: ''
    }
  }),
  mutations: {
    setProfile (state, userInfo) {
      state.profile = userInfo
    },
    clearProfile (state) {
      state.profile = {}
    }
  },
  // 测试代码
  // mutations: {
  //   setUser (state) {
  //     state.id = 'hh'
  //   }
  // }
  actions: {
    asyncGetUserInfo (ctx, { account, password }) {
      return new Promise((resolve, reject) => {
        userAccountLogin({ account, password }).then(res => {
          ctx.commit('setProfile', res.result)
          resolve()
        })
      })
    }
  }
}
export default user
